import prompt from '@system.prompt';
import router from '@system.router';
import http from '@ohos.net.http';
export default {
    data: {
        title: 'World',
        user: {
            "userId": null, "userName": null, "userPassword": null,
            "userQuestion": null, "userAnswer": null, "userImagePath": null
        },

        ReinputNewPassword:""
    },

    getUserName(event){
        this.user.userName = event.value;
    },

    userQuestionQuery(){
        let httpRequest = http.createHttp();
        httpRequest.request(
        // 填写http请求的url地址，可以带参数也可以不带参数。URL地址需要开发者自定义。GET请求的参数可以在extraData中指定
        this.$app.$def.getUserQuestionUrl(),
            {
                method: 'GET',
                extraData: {
                    userName: this.user.userName
                }
            }, (err, data) => {
            if (!err) {
                // data.result为http响应内容，可根据业务需要进行解析
                console.info('Result:' + data.result);
                console.log("--------->")
                this.$app.$def.globalData.jsonResult = JSON.parse(data.result);
                if(this.$app.$def.globalData.jsonResult.code == 1){
                    this.user.userQuestion=this.$app.$def.globalData.jsonResult.info;
                    prompt.showToast({
                        message: this.$app.$def.globalData.jsonResult.msg,
                        duration: 2000,
                    });
                }
                else{
                    this.msg = this.$app.$def.globalData.jsonResult.msg
                    prompt.showToast({
                        message: this.msg,
                        duration: 2000,
                    });
                }
                // data.header为http响应头，可根据业务需要进行解析
                console.info('header:' + data.header);
            } else {
                console.info('error:' + err.data);
            }
        }
        );
    },

    QueryReset(){
        let httpRequest = http.createHttp();
        httpRequest.request(
        // 填写http请求的url地址，可以带参数也可以不带参数。URL地址需要开发者自定义。GET请求的参数可以在extraData中指定
        this.$app.$def.getUserModify(),
            {
                method: 'POST',
                header: {
                    'Content-Type': 'application/json',
                },
                extraData: {
                    userName: this.user.userName,
                    userQuestion:this.user.userQuestion,
                    userAnswer:this.user.userAnswer,
                    goalUserPassword:this.user.userPassword
                }
            }, (err, data) => {
            if (!err) {
                // data.result为http响应内容，可根据业务需要进行解析
                console.info('Result:' + data.result);
                console.log("--------->")
                this.$app.$def.globalData.jsonResult = JSON.parse(data.result);
                if(this.$app.$def.globalData.jsonResult.code == 1){
                    prompt.showToast({
                        message: this.$app.$def.globalData.jsonResult.msg,
                        duration: 2000,
                    });
                }
                else{
                    this.msg = this.$app.$def.globalData.jsonResult.msg
                    prompt.showToast({
                        message: this.msg,
                        duration: 2000,
                    });
                }
                // data.header为http响应头，可根据业务需要进行解析
                console.info('header:' + data.header);
            } else {
                console.info('error:' + err.data);
            }
        }
        );
    },
    getNewPassword(event){
        this.user.userPassword = event.value;
    },

    getReinputNewPassword(event){
        this.ReinputNewPassword=event.value;
    },

    getQuestion(event){
        this.user.userQuestion=event.value;
    },

    getQuestionAnswer(event){
      this.user.userAnswer=event.value;
    },

    resetpassword(){
        if(this.user.userPassword==this.ReinputNewPassword){
            this.QueryReset();
        }
        else{
            prompt.showToast({
                message: "两次输入的密码不一致",
                duration: 2000,
            });
        }

    }

}
